<template>
    <div class="filter">
        <div class="filter-item">
            <label for="">所属单位：</label>
            <el-select
                v-model="searchForm.depId"
                class="m-2"
                style="width: 145px"
                :disabled="localTypeUnit != '1'"
            >
                <el-option
                    v-for="item in depIdList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                />
            </el-select>
        </div>
        <div class="filter-item">
            <label for="">日报日期：</label>
            <el-date-picker
                style="width: 145px"
                v-model="searchForm.entryDate"
                format="YYYY-MM-DD"
                type="date"
                :size="'default'"
                @change="taskDateChange"
            />
        </div>
        <div class="filter-item">
            <el-button
                size="default"
                type="primary"
                @click="search"
            >查询</el-button>
            <el-button
                size="default"
                @click="reset"
            >重置</el-button>
        </div>
    </div>

    <div class="filter">
        <div class="filter-item">
            <el-button
                type="primary"
                @click="handleClick('add')"
            >新增</el-button>
        </div>
    </div>

    <el-table
        :data="tableData"
        style="width: 100%"
        id="inspectionTask"
    >
        <el-table-column
            prop="title"
            label="所属单位"
        >
            <template #default="scope">
                {{ depNameTranslate(scope.row.depId) }}
            </template>
        </el-table-column>
        <el-table-column
            prop="entryDate"
            label="检测日期"
        />
        <el-table-column
            prop="indicatorName"
            label="检测指标"
        />
        <el-table-column
            prop="indicatorType"
            label="样品来源"
        />
        <el-table-column
            prop="result"
            label="检测结果"
        />
        <el-table-column
            prop="detectionUser"
            label="检测人员"
        />
        <el-table-column
            prop="reviewUser"
            label="复核人员"
        />
        <el-table-column
            fixed="right"
            label="操作"
            width="80"
        >
            <template #default="scope">
                <el-button
                    type="primary"
                    size="small"
                    :icon="View"
                    @click="handleClick('detail', scope.row)"
                >
                </el-button>
            </template>
        </el-table-column>

    </el-table>
    <!-- <el-pagination
        v-model:current-page="searchForm.pageNo"
        v-model:page-size="searchForm.pageSize"
        layout="total, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        class="paginationStyle"
    /> -->

    <el-dialog
        v-model="configVisible"
        :title="configTitle"
        style="min-width: 1092px"
        width="1092"
        :fullscreen="fullScreen"
        :show-close="false"
    >
        <template #header="{ titleClass }">
            <div class="my-header">
                <h4 :class="titleClass">{{configTitle}}</h4>
                <div class="rightBtn">
                    <el-icon
                        class="el-icon--left"
                        @click="fullscreenFn"
                        size="18"
                        color="#fff"
                        v-if="!fullScreen"
                        style=" margin-right: 12px;"
                    >
                        <FullScreen />
                    </el-icon>

                    <img
                        v-else
                        src="@/assets/images/closefull3.png"
                        alt=""
                        @click="fullscreenFn"
                        style=" width: 24px;height: 24px; margin-right: 12px;"
                    >
                    <el-icon
                        class="el-icon--left"
                        @click="configVisible = false,fullScreen = false"
                        size="20"
                        color="#fff"
                    >
                        <Close />
                    </el-icon>
                </div>
            </div>
        </template>
        <configNormal
            :taskSearchForm="searchForm"
            ref="configNormalRef"
            v-if="configVisible"
            @closed="configVisible = false"
        >
        </configNormal>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="configVisible = false">取消</el-button>
                <el-button
                    type="primary"
                    @click="reviewConfirm()"
                    v-loading="confirmLoading"
                    v-show="handleClickType == 'review'"
                >
                    复核
                </el-button>
                <el-button
                    type="primary"
                    @click="checkConfirm()"
                    v-loading="confirmLoading"
                    v-show="handleClickType == 'check'"
                >
                    审核
                </el-button>
            </div>
        </template>
    </el-dialog>
    <el-dialog
        v-model="configOtherVisible"
        :title="configOtherTitle"
        style="min-width: 1092px"
        :fullscreen="fullScreen"
        :show-close="false"
    >
        <template #header="{ titleClass }">
            <div class="my-header">
                <h4 :class="titleClass">{{configOtherTitle}}</h4>
                <div class="rightBtn">
                    <el-icon
                        class="el-icon--left"
                        @click="fullscreenFn"
                        size="18"
                        color="#fff"
                        v-if="!fullScreen"
                        style=" margin-right: 12px;"
                    >
                        <FullScreen />
                    </el-icon>

                    <img
                        v-else
                        src="@/assets/images/closefull3.png"
                        alt=""
                        @click="fullscreenFn"
                        style=" width: 24px;height: 24px; margin-right: 12px;"
                    >
                    <el-icon
                        class="el-icon--left"
                        @click="configOtherVisible = false,fullScreen = false"
                        size="20"
                        color="#fff"
                    >
                        <Close />
                    </el-icon>
                </div>
            </div>
        </template>
        <configOther3169_0
            ref="configOther3169Ref_0"
            :taskSearchForm="searchForm"
            @closed="configOtherVisible = false"
            v-if="configOtherVisible && handleClickTaskType == 3169 && handleClickTaskTypeName == 'MLSS'"
        ></configOther3169_0>
        <configOther3169_1
            ref="configOther3169Ref_1"
            :taskSearchForm="searchForm"
            @closed="configOtherVisible = false"
            v-if="configOtherVisible && handleClickTaskType == 3169 && handleClickTaskTypeName == 'MLVSS'"
        ></configOther3169_1>
        <configOther3298
            :taskSearchForm="searchForm"
            ref="configOther3298Ref"
            @closed="configVisible = false"
            v-if="configOtherVisible && handleClickTaskType == 3298"
        >
        </configOther3298>
        <configOther3289
            ref="configOther3289Ref"
            :taskSearchForm="searchForm"
            @closed="configOtherVisible = false"
            v-if="configOtherVisible && handleClickTaskType == 3289"
        ></configOther3289>
        <configOther1600
            ref="configOther1600Ref"
            :taskSearchForm="searchForm"
            @closed="configOtherVisible = false"
            v-if="configOtherVisible && handleClickTaskType == 1600"
        ></configOther1600>
        <configOther2922
            ref="configOther2922Ref"
            :taskSearchForm="searchForm"
            @closed="configOtherVisible = false"
            v-if="configOtherVisible && handleClickTaskType == 2922"
        ></configOther2922>
        <configOther3277
            ref="configOther3277Ref"
            :taskSearchForm="searchForm"
            @closed="configOtherVisible = false"
            v-if="configOtherVisible && handleClickTaskType == 3277"
        ></configOther3277>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="configOtherVisible = false">取消</el-button>
                <el-button
                    type="primary"
                    @click="reviewConfirm()"
                    v-loading="confirmLoading"
                    v-show="handleClickType == 'review'"
                >
                    复核
                </el-button>
                <el-button
                    type="primary"
                    @click="checkConfirm()"
                    v-loading="confirmLoading"
                    v-show="handleClickType == 'check'"
                >
                    审核
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup>
// utils
import taskHttp from "@/https/task.js";
import dataCenterHttp from "@/https/dataCenter.js";
import Storage from "@/utils/storage.js";
import moment from 'moment';
import {
    Delete,
    Edit,
    View
} from "@element-plus/icons-vue";
import ConfigNormal from '../../daysTask/dialogComponents/configNormal.vue';
import configOther3169_0 from './mlssmlvss/configOther3169_0.vue';
import configOther3169_1 from './mlssmlvss/configOther3169_1.vue';
import ConfigOther1600 from '../../daysTask/dialogComponents/configOther1600.vue';
import ConfigOther3289 from '../../daysTask/dialogComponents/configOther3289.vue';
import ConfigOther2922 from '../../daysTask/dialogComponents/configOther2922.vue';
import ConfigOther3277 from '../../daysTask/dialogComponents/configOther3277.vue';
import ConfigOther3298 from '../../daysTask/dialogComponents/configOther3298.vue';
import { ref, onMounted, nextTick } from "vue";
import { ElMessage } from "element-plus";

let searchForm = ref({
    depId: Storage.localGet("depId"),
    entryDate: moment().format('YYYY-MM-DD'),
    pageNo: 1,
    pageSize: 10,
});
const localTypeUnit = ref(Storage.localGet("depId"));
// dict
const depIdList = ref([
    { label: "公司", value: "1" },
    { label: "星沙厂", value: "2" },
    { label: "城西厂", value: "3" },
    { label: "城北厂", value: "4" },
    { label: "城南厂", value: "5" },
    { label: "城东厂", value: "6" },
]);
const depNameTranslate = (depId) => {
    let depName = "";
    depIdList.value.forEach((item) => {
        if (item.value == depId) {
            depName = item.label;
        }
    });
    return depName;
};
let tableData = ref([]);
let total = ref(0);
const handleSizeChange = (val) => {
    searchForm.pageSize = val;
    search();
};
const handleCurrentChange = (val) => {
    searchForm.pageNo = val;
    search();
};
// 重置
const reset = async () => {
    searchForm.value.depId = Storage.localGet("depId")
    searchForm.value.entryDate = moment().format('YYYY-MM-DD')
    searchForm.value.pageNo = 1
    searchForm.value.pageSize = 10
    search()
}
// 查询
const search = async () => {
    searchForm.value.entryDate = moment(searchForm.value.entryDate).format('YYYY-MM-DD')
    const res = await dataCenterHttp.recordsCenterQueryTemporaryResult(searchForm.value)
    console.log(res.data.data, 'res')
    tableData.value = res.data.data ? res.data.data : []
    // total.value = res.data.data.total
}
const configNormalRef = ref(null)
const configOther3289Ref = ref(null)
const configOther1600Ref = ref(null)
const configOther3169Ref = ref(null)
const configOther2922Ref = ref(null)
const configOther3277Ref = ref(null)
const configOther3298Ref = ref(null)
const configOther3169Ref_0 = ref(null)
const configOther3169Ref_1 = ref(null)
const configVisible = ref(false)
const configTitle = ref('')
const configOtherVisible = ref(false)
const configOtherTitle = ref('')
const handleClickType = ref()
const handleClickTaskType = ref()
const handleClickTaskTypeName = ref()
const handleClick = async (type, row) => {
    console.log(row, 'row', row.taskId)
    handleClickType.value = type
    handleClickTaskType.value = row.taskId
    handleClickTaskTypeName.value = row.indicatorName
    row.id = row.taskId
    let reportType = type == 'review' ? '[复核]' : type == 'check' ? '[审核]' : ''
    if (type == 'detail' || type == 'review' || type == 'check') {
        console.log(row, 'row11111----------', handleClickTaskType.value == 3169, row.indicatorName)

        if (handleClickTaskType.value == 2922) {
            configOtherVisible.value = true
            configOtherTitle.value = row.indicatorName + reportType
            nextTick(() => {
                console.log(configOther2922Ref.value, 'configOther2922Ref.value')
                configOther2922Ref.value.init(type, row)
            })
        } else if (handleClickTaskType.value == 3298) {
            configOtherVisible.value = true
            configOtherTitle.value = row.indicatorName + reportType
            nextTick(() => {
                console.log(configOther3298Ref.value, 'configOther3298Ref.value')
                configOther3298Ref.value.init(type, row)
            })
        } else if (handleClickTaskType.value == 3277) {
            configOtherVisible.value = true
            configOtherTitle.value = row.indicatorName + reportType
            nextTick(() => {
                console.log(configOther3277Ref.value, 'configOther3277Ref.value')
                configOther3277Ref.value.init(type, row)
            })
        } else if (handleClickTaskType.value == 3289) {
            configOtherVisible.value = true
            configOtherTitle.value = row.indicatorName + reportType
            nextTick(() => {
                console.log(configOther3289Ref.value, 'configOther3289Ref.value')
                configOther3289Ref.value.init(type, row)
            })

        } else if (handleClickTaskType.value == 1600) {
            configOtherVisible.value = true
            configOtherTitle.value = row.indicatorName + reportType
            nextTick(() => {
                console.log(configOther1600Ref.value, 'configOther1600Ref.value')
                configOther1600Ref.value.init(type, row)
            })

        } else if (handleClickTaskType.value == 3169 && row.indicatorName == 'MLSS') {
            configOtherVisible.value = true
            configOtherTitle.value = row.indicatorName + reportType
            nextTick(() => {
                console.log(configOther3169Ref_0.value, 'configOther3169Ref_0.value')
                configOther3169Ref_0.value.init(type, row)
            })
        } else if (handleClickTaskType.value == 3169 && row.indicatorName == 'MLVSS') {
            configOtherVisible.value = true
            configOtherTitle.value = row.indicatorName + reportType
            nextTick(() => {
                console.log(configOther3169Ref_1.value, 'configOther3169Ref_1.value')
                configOther3169Ref_1.value.init(type, row)
            })
        } else {
            configVisible.value = true
            configTitle.value = row.indicatorName + reportType
            nextTick(() => {
                configNormalRef.value.init(type, row)
            })
        }
    }
}
onMounted(() => {
    search()
})
</script>